package com.itheima.并发工具类.CountDownLatch;

import java.util.concurrent.CountDownLatch;

public class MyCountDownLatch {
    public static void main(String[] args) {
        /*
        1. CountDownLatch(int count)：参数写等待线程的数量。并定义了一个计数器。
​	    2. await()：让线程等待，当计数器为0时，会唤醒等待的线程
​	    3. countDown()： 线程执行完毕时调用，会将计数器-1。
         */
        CountDownLatch cdl = new CountDownLatch(3);
        MotherThread m = new MotherThread(cdl);
        m.start();

        Child1 c1 = new Child1(cdl);
        c1.setName("大儿子");
        Child2 c2 = new Child2(cdl);
        c2.setName("二儿子");
        Child3 c3 = new Child3(cdl);
        c3.setName("小女儿");

        c1.start();
        c2.start();
        c3.start();

    }
}
